import store from '@/store'
import { Message } from 'element-ui';
export const useWs = (callback) => {
  const webSocketUrl = process.env.VUE_APP_WS_URL + '/' + store.state.user.id
  const webSocket = new WebSocket(webSocketUrl)
  webSocket.onopen = function(event) {
  }
  webSocket.onmessage = function(event) {
    const msg = JSON.parse(event.data)
    if (msg.type === 'success') {
      Message.success( '生码成功');
      callback()
    }
    if (msg.type === 'error') {
      Message.success('生码失败')
      window.location.reload()
    }
  }
  webSocket.onclose = function(event) {
  }
  webSocket.onerror = function(event) {
    console.log(event)
  }
}
// 获取字典Label
export const getDictLabel = (dictList, dictType, dictValue) => {
  const type = dictList.find((element) => element.value === dictType)
  console.log(type)
  if (type) {
    return type.label
  } else {
    return dictValue
  }
}
